<?php

	require_once("../connectMysql/connetMysql.class.php");
	$actid = $_GET['actId']; //获取actid
	$aplytype=$_GET['aplytype'];//获取报名参数
	$mobile=$_GET['mobile'];
	$db=new connetMysql;
	$con=$db->getConnect();
	$applypost_sql="SELECT UserId FROM user WHERE UserPhone=".$mobile;	
	$result=mysqli_query($con,$applypost_sql);
	$row = mysqli_fetch_assoc($result);	
	$userid=$row["UserId"];
	
	$chk_sql="SELECT ActApplyId FROM actapply WHERE UserId=".$userid." AND ActivityId=".$actid;	
	mysqli_query($con,$chk_sql);
	$num=mysqli_affected_rows($con);
	if($num==0)
	{
		$inserapply_sql="INSERT INTO actapply(UserId,ActivityId) VALUES(".$userid.",".$actid.")";	
		mysqli_query($con,$inserapply_sql);
		$num2=mysqli_affected_rows($con);
		if($num2!=0)
		{
			$success_respon = array('code' => 'SUCCESS_APPLY', 'msg' => '1');
			echo json_encode($success_respon);//报名成功
		}
		else
		{
			$success_respon = array('code' => 'ERROR_APPLY', 'msg' => '3');
			echo json_encode($success_respon);//未知错误
		}
		$db->clossConnet();
		
	}
	else if($aplytype=="0"&&$num!=0)
	{
		$delete_sql="DELETE FROM actapply WHERE UserId=".$userid." AND ActivityId=".$actid;	
		mysqli_query($con,$delete_sql);
		$success_respon = array('code' => 'SUCCESS_CANCEL', 'msg' => '4');
			echo json_encode($success_respon);//取消成功
	}
	else 
	{
		$success_respon = array('code' => 'ERROR', 'msg' => '2');
		echo json_encode($success_respon);//已报名
		
	}
	
?>